package DBUtil

import (
	"GoIP/Server"
	_ "GoIP/Server"
	"database/sql"
	_ "github.com/go-sql-driver/mysql"
)

// DBConfig represents the configuration of the database.
type DBConfig struct {
	Host     string
	Port     string
	User     string
	Password string
	Database string
	Charset  string
}

func InsertMsg(data Server.Userdata, db *sql.DB) (int64,error) {
	// Insert message into database
	sqlStr := "INSERT INTO messages (User_id,Shop_id,msg,time) VALUES (data.Id,data.Shopid,data.Message,data.Time)"
	exec, err := db.Exec(sqlStr)
	if err != nil {
		return 0,err
	}
	n, _ := exec.RowsAffected()
	if n == 0 {
		return 0,err
	}
	return n,nil
}
